package com.mentorgen.tools.util.profile.bundle;

import java.io.PrintWriter;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;

import org.osgi.framework.BundleActivator;
import org.osgi.framework.BundleContext;
import org.osgi.framework.hooks.service.EventHook;
import org.osgi.framework.hooks.service.FindHook;

import com.mentorgen.tools.util.profile.ClientHelper;

public class ClientActivator implements BundleActivator {

	private BundleContext context;

	private Thread profilingThread;

	@Override
	public void start(BundleContext _context) throws Exception {

		this.context = _context;

//		LoggerHooks loggerHooks = new LoggerHooks(context);
//        context.registerService(new String[]{FindHook.class.getName(),
//        		EventHook.class.getName()}, loggerHooks, null);

		DateFormat dateFormat = new SimpleDateFormat("yyyyMMdd-HHmmss");
	    Date date = new Date();
		String profilingFile = "Profile-" + dateFormat.format(date);

		System.out.println("Profiling File: " + profilingFile);

		OSGiServiceProfiler profiler = new OSGiServiceProfiler(profilingFile, context);
		profilingThread = new Thread(profiler);
		profilingThread.start();
	}

	@Override
	public void stop(BundleContext context) throws Exception {

		profilingThread.interrupt();

	}
}
